﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyThuVien.Business;

namespace QuanLyThuVien.Presentation
{
    public partial class frmQuanLyTraSach : Form
    {
        public frmQuanLyTraSach()
        {
            InitializeComponent();
        }
        PhieuMuonBUS BusPhieumuon = new PhieuMuonBUS();

        PhieuMuon Phieumuon = new PhieuMuon();

        private void frmQuanLyTraSach_Load(object sender, EventArgs e)
        {
            BusPhieumuon.LoadLenDataGridView(dgMuon);
        }

        private void dgMuon_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int a = e.RowIndex;
            cbTenSachM.Text = dgMuon[0, a].Value.ToString();
            cbChuyenNganhM.Text = dgMuon[1, a].Value.ToString();
            lbMaDSM.Text = dgMuon[2, a].Value.ToString();
            cbMaSachM.Text = dgMuon[3, a].Value.ToString();
            cbMaThe.Text = dgMuon[4, a].Value.ToString();
            lbTenDG.Text = dgMuon[5, a].Value.ToString();
            mkNgayMuon.Text = dgMuon[6, a].Value.ToString();
            mkNgayTra.Text = dgMuon[7, a].Value.ToString();
        }

        private void btTra_Click_1(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Bạn có muốn trả sách không?", "QuanLyThuVien", MessageBoxButtons.YesNo, MessageBoxIcon.None) == DialogResult.Yes)
                {
                    Phieumuon.MaSach = cbMaSachM.Text;
                    Phieumuon.MaThe = cbMaThe.Text;
                    Phieumuon.NgayMuon = mkNgayMuon.Text;
                    Phieumuon.NgayTra1 = mkNgayTra.Text;
                    BusPhieumuon.TraSach(Phieumuon);
                    BusPhieumuon.LoadLenDataGridView(dgMuon);
                    cbTenSachM.Text = "";
                    cbChuyenNganhM.Text = "";
                    lbMaDSM.Text = "";
                    cbMaSachM.Text = "";
                    cbMaThe.Text = "";
                    lbTenDG.Text = "";
                    mkNgayMuon.Text = "";
                    mkNgayTra.Text = "";
                    MessageBox.Show("Bạn trả sách thành công.", "QuanLyThuVien");
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message, "QuanLyThuVien");
            }
        }

        private void btThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
